package github.kawaiior.yuanchuxiuzhen.common.item.armor;

import github.kawaiior.yuanchuxiuzhen.core.init.ItemInit;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.LazyValue;
import net.minecraft.util.SoundEvents;

import java.util.function.Supplier;

public enum ModArmorMaterial implements IArmorMaterial {

    //OBSIDIAN("obsidian", 40, new int[]{5, 8, 10, 5}, 20, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 2.0F, 0.0F, () -> {
    //        return Ingredient.fromItems(ItemRegistry.obsidianIngot.get());
    //    });

    MANA_STONE_ARMOR_1("mana_stone_armor_1", 40, new int[]{2, 5, 6, 2}, 20,
            SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 2.0F, 0.0F, ()->{
        return Ingredient.fromItems(ItemInit.MANA_STONE_ITEM_LEVEL_9.get());
    }),
    MANA_STONE_ARMOR_2("mana_stone_armor_2", 40, new int[]{3, 6, 7, 3}, 20,
    SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 2.5F, 0.0F, ()->{
        return Ingredient.fromItems(ItemInit.MANA_STONE_ITEM_LEVEL_9.get());
    }),
    MANA_STONE_ARMOR_3("mana_stone_armor_3", 40, new int[]{4, 7, 8, 4}, 20,
    SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 3.0F, 0.0F, ()->{
        return Ingredient.fromItems(ItemInit.MANA_STONE_ITEM_LEVEL_9.get());
    }),
    MANA_STONE_ARMOR_4("mana_stone_armor_4", 40, new int[]{5, 8, 9, 5}, 20,
    SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 3.5F, 0.0F, ()->{
        return Ingredient.fromItems(ItemInit.MANA_STONE_ITEM_LEVEL_9.get());
    }),
    MANA_STONE_ARMOR_5("mana_stone_armor_5", 40, new int[]{6, 9, 10, 6}, 20,
    SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 4.0F, 0.0F, ()->{
        return Ingredient.fromItems(ItemInit.MANA_STONE_ITEM_LEVEL_9.get());
    }),
    MANA_STONE_ARMOR_6("mana_stone_armor_6", 40, new int[]{7, 10, 11, 7}, 20,
    SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 4.5F, 0.0F, ()->{
        return Ingredient.fromItems(ItemInit.MANA_STONE_ITEM_LEVEL_9.get());
    }),
    MANA_STONE_ARMOR_7("mana_stone_armor_7", 40, new int[]{8, 11, 12, 8}, 20,
    SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 5.0F, 0.0F, ()->{
        return Ingredient.fromItems(ItemInit.MANA_STONE_ITEM_LEVEL_9.get());
    }),
    MANA_STONE_ARMOR_8("mana_stone_armor_8", 40, new int[]{9, 12, 13, 9}, 20,
    SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 5.5F, 0.0F, ()->{
        return Ingredient.fromItems(ItemInit.MANA_STONE_ITEM_LEVEL_9.get());
    }),
    MANA_STONE_ARMOR_9("mana_stone_armor_9", 40, new int[]{10, 13, 14, 10}, 20,
    SoundEvents.ITEM_ARMOR_EQUIP_GOLD, 6.0F, 0.0F, ()->{
        return Ingredient.fromItems(ItemInit.MANA_STONE_ITEM_LEVEL_9.get());
    });


    private static final int[] MAX_DAMAGE_ARRAY = new int[]{13, 15, 16, 11};
    private final String name;
    private final int maxDamageFactor;
    private final int[] damageReductionAmountArray;
    private final int enchantability;
    private final SoundEvent soundEvent;
    private final float toughness;
    private final float knockbackResistance;
    private final LazyValue<Ingredient> repairMaterial;

    ModArmorMaterial(String name, int maxDamageFactor, int[] damageReductionAmountArray,
                     int enchantability, SoundEvent soundEvent, float toughness, float knockbackResistance,
                     Supplier<Ingredient> repairMaterial) {
        this.name = name;
        this.maxDamageFactor = maxDamageFactor;
        this.damageReductionAmountArray = damageReductionAmountArray;
        this.enchantability = enchantability;
        this.soundEvent = soundEvent;
        this.toughness = toughness;
        this.knockbackResistance = knockbackResistance;
        this.repairMaterial = new LazyValue<>(repairMaterial);
    }

    public int getDurability(EquipmentSlotType slotIn) {
        return MAX_DAMAGE_ARRAY[slotIn.getIndex()] * this.maxDamageFactor;
    }

    public int getDamageReductionAmount(EquipmentSlotType slotIn) {
        return this.damageReductionAmountArray[slotIn.getIndex()];
    }

    public int getEnchantability() {
        return this.enchantability;
    }

    public SoundEvent getSoundEvent() {
        return this.soundEvent;
    }

    public Ingredient getRepairMaterial() {
        return this.repairMaterial.getValue();
    }
    public String getName() {
        return this.name;
    }

    public float getToughness() {
        return this.toughness;
    }

    /**
     * Gets the percentage of knockback resistance provided by armor of the material.
     */
    public float getKnockbackResistance() {
        return this.knockbackResistance;
    }
}
